﻿using MediatR;
using SheepCultivation.Common.Domain;
using SheepCultivation.Common.Dto;
using SheepCultivation.Common.Infrastructure.Interface;
using SheepCultivation.Enum;

namespace SheepCultivation.API.AddliCation.AddressW
{
    public class CitySeachHandler : IRequestHandler<CitySeachCommon, Result>
    {
        public readonly IBaseRepository<City> CityRepository;

        public CitySeachHandler(IBaseRepository<City> cityRepository)
        {
            CityRepository = cityRepository;
        }

        public async Task<Result> Handle(CitySeachCommon request, CancellationToken cancellationToken)
        {
            var res = new Result() { Code = (int)CommonEnumCode.error };
            try
            {
                var list = CityRepository.GetAll().Where(x => x.ProvinceId == request.ProvionId).ToList();
                res.Code = (int)CommonEnumCode.success;
                res.Data = list;
                res.Msg = "省列表";
            }
            catch (Exception ex)
            {

            }
            return res;
        }
    }
}
